package com.cn.kabalifemerchants.ui.user.activity;

import com.cn.kabalifemerchants.api.Api;
import com.cn.kabalifemerchants.base.BasePresenter;
import com.cn.kabalifemerchants.callback.CacheCallBack;
import com.cn.kabalifemerchants.config.Constants;
import com.cn.kabalifemerchants.ui.user.bean.CashListBean;
import com.cn.kabalifemerchants.ui.user.bean.FinanceBean;
import com.cn.kabalifemerchants.ui.user.bean.MyUserInfoBean;
import com.cn.kabalifemerchants.ui.user.bean.ShouRuListBean;
import com.cn.kabalifemerchants.utils.LoggerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * Created by 晓林 on 2020/10/21.
 * function:
 */
public class FinancialDetailsPresenter extends BasePresenter<FinancialDetailsView> {

    public void onFinanceData(String token) {
        OkGo.<FinanceBean>get(Api.API_FINANCE)
                .headers("token", token)
                .execute(new CacheCallBack<FinanceBean>() {
                    @Override
                    public void onSuccess(Response<FinanceBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("财务明细" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onFinanceSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    public void onTiXianListData(String token, int page, int limit, String time) {
        OkGo.<CashListBean>get(Api.API_USER_CASH_LIST)
                .headers("token", token)
                .params("limit", limit)
                .params("page", page)
                .params("app_type", 2)
                .params("time", time)
                .execute(new CacheCallBack<CashListBean>() {
                    @Override
                    public void onSuccess(Response<CashListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("list提现：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onTiXianListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    public void onShouRuListData(String token, int page, int limit, String time) {
        OkGo.<ShouRuListBean>get(Api.API_USER_BUS_LIST)
                .headers("token", token)
                .params("limit", limit)
                .params("page", page)
                .params("app_type", 2)
                .params("time", time)
                .execute(new CacheCallBack<ShouRuListBean>() {
                    @Override
                    public void onSuccess(Response<ShouRuListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("list收入：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onShouRuListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

}
